import unittest
from tools.tools_1 import Chrome
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from os.path import join
from config.config import PROJECT_PATH

options = Options()

"""父类"""
class BaseCase(unittest.TestCase):

    def setUp(self):
        """创建浏览器驱动"""
        # 关闭密码管理功能和凭证服务
        prefs = {
            "credentials_enable_service": False,
            "profile.password_manager_enabled": False
        }
        options.add_experimental_option("prefs", prefs)

        # 禁用自动化检测（可选）
        options.add_experimental_option("excludeSwitches", ["enable-automation", "enable-logging"])
        options.add_argument("--disable-blink-features=AutomationControlled")
        service = Service(join(PROJECT_PATH, 'service','chromedriver.exe'))  # 替换为你的 chromedriver 路径
        self.driver = webdriver.Chrome(service=service, options=options)
        self.driver.maximize_window()

    def tearDown(self):
        """关闭浏览器并释放资源"""
        self.driver.quit()